/* -+- file  ./kf2/GUI/Notify.cs -+- */
/*
 * kf2 jabber client
 * ~~~~~~~~~~~~~~~~~
 *
 * Copyright (C) 2006-2007 Przemysław Sitek
 * 				<przemyslaw.sitek at wp.pl> 
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public License as
 * published by the Free Software Foundation; either version 2 of the
 * License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this program; if not, write to the
 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 * Boston, MA 02111-1307, USA.
 */

using System;
using Habazie.kf2.Exposition;

namespace Habazie.kf2.GUI
{
	
	public class GtkNotify : INotifyService
	{
		///<summary>Notification window</summary>
		private NotifyWindow m_Win = null;
		private int m_TimeoutId = -1;
		
		public GtkNotify()
		{
		//	m_Win = new NotifyWindow;
		}
		
		public void Notify (NotifyClass nclass, string text, string desc)
		{
		//	if (m_Win != null)
		//		m_Win.Destroy ();
				
			if (m_TimeoutId != -1)
				MyTimeoutHandler ();
				
			m_Win = new NotifyWindow ();
			m_Win.TextMarkup = "<b>" + text + "</b>";
			m_Win.DescMarkup = "<small><i>" + desc + "</i></small>";
			
			Gdk.Pixbuf pix = null;
			if (nclass == NotifyClass.Chat)
				pix = Gdk.Pixbuf.LoadFromResource ("pix_chat48.png");
			else if (nclass == NotifyClass.Message)
				pix = Gdk.Pixbuf.LoadFromResource ("pix_message48.png");
				
			m_Win.Pixbuf = pix;
			
			int w,h;
			m_Win.GetSize (out w, out h);
			Gdk.Screen screen = m_Win.Screen;
			m_Win.Move (screen.Width - w - 16, screen.Height - h - 16);
			
			m_Win.Show ();
			m_TimeoutId = (int) GLib.Timeout.Add (5000, MyTimeoutHandler);
		}
		
		protected bool MyTimeoutHandler ()
		{
			m_Win.Destroy ();
			m_TimeoutId = -1;
			return false;
		}
	}
}
